/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    touch-action: manipulation;
}

/* Main container - responsive height */
#app-container {
    width: 100%;
    height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Iframe-specific height adjustment */
@media (max-height: 500px) {
    #app-container {
        height: 450px;
    }
}

/* Header tooltip - appears on hover */
#header-tooltip {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(44, 62, 80, 0.95);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
    text-align: center;
    max-width: 80%;
    line-height: 1.4;
}

#app-container:hover #header-tooltip {
    opacity: 1;
}

/* Control panel for zoom functions */
#control-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 8px;
    z-index: 100;
}

.control-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(52, 152, 219, 0.9);
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: rgba(52, 152, 219, 1);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.control-btn:active {
    transform: scale(0.95);
}

/* Map container */
#map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(to bottom, #87CEEB 0%, #98FB98 100%);
    border-radius: 10px;
    margin: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

/* SVG map styling */
#map-svg {
    width: 100%;
    height: 100%;
    cursor: grab;
    transition: transform 0.3s ease;
}

#map-svg:active {
    cursor: grabbing;
}

/* Country styling */
.country {
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}

.country:hover {
    transform: scale(1.05);
    filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.4));
    opacity: 0.9;
}

.country:active {
    transform: scale(0.98);
}

/* Country labels */
.country-label {
    font-size: 12px;
    font-weight: bold;
    fill: white;
    text-anchor: middle;
    pointer-events: none;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

/* Historical border styling */
.border-label {
    font-size: 10px;
    font-weight: bold;
    fill: #2C3E50;
    text-anchor: middle;
    pointer-events: none;
    opacity: 0.8;
}

/* City markers and labels */
.city-marker {
    pointer-events: none;
}

.city-label {
    font-size: 9px;
    font-weight: normal;
    fill: #2C3E50;
    pointer-events: none;
}

/* River styling */
.river {
    pointer-events: none;
}

.river-label {
    font-size: 9px;
    font-style: italic;
    fill: #2980B9;
    text-anchor: middle;
    pointer-events: none;
    opacity: 0.8;
}

/* Superpower indicators */
.superpower {
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}

.superpower:hover {
    transform: scale(1.1);
    filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.4));
}

.superpower-label {
    font-size: 10px;
    font-weight: bold;
    fill: white;
    pointer-events: none;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

/* Conflict markers */
.conflict-marker {
    pointer-events: none;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.5));
}

/* Information popup */
.popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    max-width: 400px;
    width: 90%;
    max-height: 70%;
    overflow-y: auto;
    z-index: 200;
    transition: all 0.3s ease;
}

.popup.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.8);
}

.popup-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popup-header h3 {
    margin: 0;
    font-size: 18px;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.close-btn:hover {
    background-color: rgba(255,255,255,0.2);
}

.popup-content {
    padding: 20px;
    line-height: 1.6;
    color: #2c3e50;
}

.popup-content p {
    margin-bottom: 15px;
}

/* Timeline panel */
#timeline-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255,255,255,0.95);
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    min-width: 250px;
    max-width: 300px;
}

.timeline-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

#timeline-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

#timeline-toggle.expanded {
    transform: rotate(180deg);
}

#timeline-content {
    max-height: 200px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

#timeline-content.hidden {
    max-height: 0;
    overflow: hidden;
}

.timeline-item {
    padding: 10px 16px;
    border-bottom: 1px solid #ecf0f1;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex;
    gap: 12px;
}

.timeline-item:hover {
    background-color: #f8f9fa;
}

.timeline-item:last-child {
    border-bottom: none;
}

.year {
    font-weight: bold;
    color: #667eea;
    min-width: 45px;
}

.event {
    color: #2c3e50;
    flex: 1;
}

/* Tooltip utility class */
.tooltip {
    position: absolute;
    background: rgba(44, 62, 80, 0.95);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 200px;
    text-align: center;
    line-height: 1.4;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    .popup {
        width: 95%;
        max-width: none;
    }
    
    .country-label {
        font-size: 10px;
    }
    
    .superpower-label {
        font-size: 8px;
    }
    
    .city-label, .river-label, .border-label {
        font-size: 8px;
    }
    
    #timeline-panel {
        min-width: 200px;
        max-width: 250px;
    }
    
    .timeline-item {
        padding: 8px 12px;
    }
    
    .year {
        min-width: 40px;
        font-size: 12px;
    }
    
    .event {
        font-size: 12px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .country:hover,
    .superpower:hover,
    .control-btn:hover,
    .timeline-item:hover {
        transform: none;
        filter: none;
        background-color: initial;
    }
    
    .country:active,
    .superpower:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
    
    .control-btn:active {
        transform: scale(0.9);
    }
}